package com.demo.mybatis.manual.config;

import java.sql.SQLException;
import java.util.Properties;
import javax.sql.DataSource;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceFactory;
import org.apache.ibatis.datasource.DataSourceFactory;

/**
 * 实现 org.apache.ibatis.datasource.DataSourceFactory
 */
public class MybatisDruidDatasource implements DataSourceFactory {

    private Properties properties;

    @Override
    public DataSource getDataSource() {
        //初始化连接
        try {
            // this.properties.setProperty("initialSize", "5");

            return DruidDataSourceFactory.createDataSource(this.properties);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     *
     * 自动加载配置 参考 com.alibaba.druid.pool.DruidDataSourceFactory
     *
     * @param properties
     */
    @Override
    public void setProperties(Properties properties) {
        this.properties = properties;
    }
}